package biz.datalk.industrialland.common.util;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.util.Date;

/**
 * @author tarofang@163.com
 * @date 2024-01-22
 */
@Slf4j
public class LogDateUtil {
    private static final String LOG_FMT = "yyyy-MM-dd_HH:mm:ss";
    public static String formatNoEx(Date date) {
        return formatNoEx(date, LOG_FMT);
    }
    public static String formatNoEx(Date date, String fmt) {
        try {
            return DateFormatUtils.format(date, fmt);
        } catch (Exception ex) {
            log.warn("{}", ex.getMessage());
            return String.valueOf(date);
        }
    }

    public static String formatNoEx(Long millis) {
        return formatNoEx(millis, LOG_FMT);
    }
    public static String formatNoEx(Long millis, String fmt) {
        try {
            return DateFormatUtils.format(millis, fmt);
        } catch (Exception ex) {
            log.warn("{}", ex.getMessage());
            return String.valueOf(millis);
        }
    }
}
